package com.antu.first.util;

import com.google.code.kaptcha.Constants;

import javax.servlet.http.HttpServletRequest;

/**
 * 验证码工具，用于判断验证码是否正确
 * Created by Administrator on 2018/3/4.
 */
public class CodeUtil {

    /**
     *验证验证码是否与预期相符
     * @param request
     * @return
     */
    public static boolean checkVerifyCode(HttpServletRequest request){
        String verifyCodeExpected=(String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        String verifyCodeActual=HttpServletRequestUtil.getString(request, "verifyCodeActual");
        if(verifyCodeActual==null || !verifyCodeExpected.equals(verifyCodeActual)){
            return false;
        }
        return true;
    }

}
